﻿$.extend($.fn.datagrid.methods, {
    mergeGridColCells: function (jq, param) {
        var rows = jq.datagrid('getRows');
        if (rows.length < 1) {
            return;
        }
        if (param.length==0) {
            return;
        }
        else {

            for (var i = 0; i < param.length; i++) {
                var rowFildName = param[i];
                var startIndex = 0;
                var endIndex = 0;
                $.each(rows, function (i, row) {
                    if (row[rowFildName] == rows[startIndex][rowFildName]) {
                        endIndex = i;
                    }
                    else {
                        jq.datagrid('mergeCells', {
                            index: startIndex,
                            field: rowFildName,
                            rowspan: endIndex - startIndex + 1
                        });
                        startIndex = i;
                        endIndex = i;
                    }

                });
                jq.datagrid('mergeCells', {
                    index: startIndex,
                    field: rowFildName,
                    rowspan: endIndex - startIndex + 1
                });
            }
        }



    }
})
